package com.zyh.thread;

/**
 * @Author zyh
 * @Date 2024/8/7 16:17
 * @Description 线程合并
 */

public class ThreadDemo7 {
    public static void main(String[] args) {
        MyTask04 myTask04 = new MyTask04();
        Thread t1 = new Thread(myTask04, "线程A");
        t1.start();
        for (int i = 0; i < 10; i++) {
            if (i==2){
                try {
                    t1.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName()+"正在打印"+i);
        }

    }
}
class MyTask04 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"正在打印"+i);
        }
    }
}
